//
// Created by grg on 2020/8/4.
// Copyright (c) 2020 龚任根. All rights reserved.
//

#ifndef TEST_CPP_PROJECT_SDLWINDOWCOMPONENT_H
#define TEST_CPP_PROJECT_SDLWINDOWCOMPONENT_H


#include <SDL2/SDL.h>
#include "iostream"

using namespace std;

const char *Window_Name = "MySDLGame";
const int Window_Width = 600;
const int Window_Height = 300;

class SDLWindowComponent {

private:
    SDL_Window *window;
    SDL_Surface *windowSurf;
    SDL_Renderer *render;

public:
    SDL_Window *getWindow() const {
        return window;
    }

    SDL_Surface *getWindowSurf() const {
        return windowSurf;
    }

    SDL_Renderer *getRender() const {
        return render;
    }

public:
    SDLWindowComponent() {
        if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
            cout << SDL_GetError() << endl;
            exit(0);
        }

        //window
        window = SDL_CreateWindow(Window_Name,
                SDL_WINDOWPOS_UNDEFINED,
                SDL_WINDOWPOS_UNDEFINED,
                Window_Width,
                Window_Height,
                SDL_WINDOW_SHOWN);

        if (window == nullptr) {
            const char *extractedExpr = SDL_GetError();
            cout << extractedExpr << endl;
            exit(0);
        }

        windowSurf = SDL_GetWindowSurface(window);
        render = SDL_GetRenderer(window);

    }

    ~SDLWindowComponent() {

        SDL_FreeSurface(windowSurf);
        SDL_DestroyRenderer(render);
        SDL_DestroyWindow(window);

        SDL_Quit();

    }


};


#endif //TEST_CPP_PROJECT_SDLWINDOWCOMPONENT_H
